from django.shortcuts import render
from django.http import HttpResponse
from .models import QuestionType,Question,Choice,Answer,PaperKu

# Create your views here.

'''单选题 = [5，2],简答 = [2,10]'''
def 生成试卷(**kwargs):

    #kwargs = {'单选题':[5，2],'简答' : [2,10]}
    
    for 题型,信息 in kwargs.items():
        
        题型类 = QuestionType.objects.get(
            question_type = 题型)

        
        question_list = 题型类.question_set.all()
        #question_list = [question.id for question in question_list]

        信息.append(question_list)

        kwargs[题型]=信息

    return kwargs
    



def paper(request):
    post_info = dict(request.POST)
    print(post_info)
    题型 = post_info['类型']
    数量 = post_info['数量']
    分数 = post_info['分数']
	
    dict_info = {题型[i]:[数量[i],分数[i]] for i in range(len(题型)) if 题型[i] != ''}
    print(dict_info)
    #{'单选题': ['5', '2']}
    #paper_info = 生成试卷(单选题 = [5,2],简答 = [2,10])
    paper_info = 生成试卷(**dict_info)
    
    #PaperKu.objects.create(paper_info = paper_info)
    #paper_info_obj = PaperKu.objects.get(pk =2)
    #paper_info_str = paper_info_obj.paper_info

    #paper_info = eval(paper_info_str)
    #x = paper_info['单选题'][2]
    print(paper_info)
    context = {}
    
    return render(request,'paper/paper.html',context)

def yunsuan(request):
    info = request.POST
    return HttpResponse(str(info))


def produce_paper(request):

	
    context = {}
    return render(request,'paper/produce_paper.html',context)




























    
    
